weiXinController.controller('kgyOrderRecallPageCtl',['$scope','$state','$stateParams','$timeout','$interval','$compile','$rootScope','$filter',function($scope,$state,$stateParams,$timeout,$interval,$compile,$rootScope,$filter) {
	console.log({name:$state.current.name,templateUrl:$state.current.templateUrl});
	// 动态title名称
	$scope.title = '';
	var un = $state.current.name;
	var mus = JSON.parse(window.localStorage.auth).menuInfo;
	for(var tmpMusKey in mus){
		if(un === mus[tmpMusKey].url){
			$scope.title = mus[tmpMusKey].name;
		}
	}

	//获取成本中心
    EdeyeAdmin.post({
        url: '/system/dict/getValueByNameAndCode',
        data: {name: 'interface.order', code: 'cost_center'},
    }, {
        SUCCESS: function (ret) {
            if (ret.code === '200') {
                var cost_center = JSON.parse(ret.data);
                for(var i = 0; i < cost_center.length; i++) {
                    $("#searchCostCenter").append("<option value='" + cost_center[i][0] + "'>" + cost_center[i][1] + "</option>");
                    if(cost_center[i][2]+''.toLowerCase().trim() == 'true') {
                        $("#statusCostCenter").append("<option value='" + cost_center[i][0] + "' selected>" + cost_center[i][1] + "</option>");
                    } else {
                        $("#statusCostCenter").append("<option value='" + cost_center[i][0] + "'>" + cost_center[i][1] + "</option>");
                    }
                }
            }
        }
    });

    //获取科目号
    EdeyeAdmin.post({
        url: '/system/dict/getValueByNameAndCode',
        data: {name: 'interface.order', code: 'account_number'},
    }, {
        SUCCESS: function (ret) {
            if (ret.code === '200') {
                var account_number = JSON.parse(ret.data);
                for(var i = 0; i < account_number.length; i++) {
                    $("#searchAccountNumber").append("<option value='" + account_number[i][0] + "'>" + account_number[i][1] + "</option>");
                    if(account_number[i][2]+''.toLowerCase().trim() == 'true') {
                        $("#statusAccountNumber").append("<option value='" + account_number[i][0] + "' selected>" + account_number[i][1] + "</option>");
                    }else {
                        $("#statusAccountNumber").append("<option value='" + account_number[i][0] + "'>" + account_number[i][1] + "</option>");
                    }
                }
            }
        }
    });
    //获取类型
    EdeyeAdmin.post({
        url: '/system/dict/getValueByNameAndCode',
        data: {name: 'interface.order', code: 'out_type'},
    }, {
        SUCCESS: function (ret) {
            if (ret.code === '200') {
                var out_type = JSON.parse(ret.data);
                for(var i = 0; i < out_type.length; i++) {
                    $("#searchOutType").append("<option value='" + out_type[i][0] + "'>" + out_type[i][1] + "</option>");
                    if(out_type[i][2]+''.toLowerCase().trim() == 'true') {
                        $("#statusOutType").append("<option value='" + out_type[i][0] + "' selected>" + out_type[i][1] + "</option>");
                    }else {
                        $("#statusOutType").append("<option value='" + out_type[i][0] + "'>" + out_type[i][1] + "</option>");
                    }
                }
            }
        }
    });

    // 备件搜索条件
    $scope.orderSearchObj = {
        bid: '',
        show_name: '',
        gmt_status: '',
        cost_center: '',
        account_number: '',
        out_type: ''
    }

    // 分页初始化条件
    var param = {
        id: 'tableDemo',
        column: [
            {
                type: 'rowNum',
                title: '编号',
            }, {
                type: 'key',
                mapping: 'id',
                show: false
            }, {
                mapping: 'show_name',
                title: '申领人'
            },{
                mapping: 'bid',
                title: '账内编号',
            },{
                mapping: 'cost_center',
                title: '成本中心',
                trans:function(data){
                    if(data.cost_center === null || data.cost_center == undefined){
                        return '';
                    }
                }
            },{
                mapping: 'account_number',
                title: '科目号',
                trans:function(data){
                    if(data.account_number === null || data.account_number == undefined){
                        return '';
                    }
                }
            },{
                mapping: 'out_type',
                title: '类型',
                trans:function(data){
                    if(data.out_type === null || data.out_type == undefined){
                        return '';
                    }
                }
            },{
                mapping: 'gmt_status',
                title: '状态',
                trans:function(data){
                    if(data.gmt_status === '0'){
                        return '未设置';
                    }
                    if(data.type_account === 'END'){
                        return '已设置';
                    }
                }
            },{
                mapping: 'gmt_modified',
                title: '操作时间'
            }, {
                type: 'function',
                title: '操作',
                titleDivStyle: 'text-align: center',
                dataDivStyle: 'text-align: center',
                func: [{
                    title: '状态',
                    css: 'btn-sm btn-outline-info',
                    text111: '<i class="fas fa-cog"></i>',
                    text: '状态',
                    show: function(data){
                        return (data.gmt_status === '0');
                    },
                    func: function (data) {
                        $scope.status(data.id, data.bid);
                    }
                }]
            }
        ],
        page: function (cmd, currentPage, pageSize, totalPageNum) {
            if ('first' === cmd) {
                currentPage = 1;
            } else if ('prev' === cmd) {
                currentPage--;
            } else if ('next' === cmd) {
                currentPage++;
            } else if ('last' === cmd) {
                currentPage = totalPageNum;
            } else if ('change' === cmd) {
                currentPage = 1;
            }

            $scope.search(currentPage, pageSize);
        }
    };
    EdeyeAdmin.initDataTablePhone(param, {data: []});


    $scope.search = function(currentPage, pageSize){
        $scope.orderSearchObj.currentPage = (currentPage === undefined ? 1 : currentPage);
        $scope.orderSearchObj.pageSize = (pageSize === undefined ? EdeyeAdmin.getPageSizePhone(param.id) : pageSize);
        $scope.orderSearchObj.cost_center = $('#searchCostCenter').val();
        $scope.orderSearchObj.account_number = $('#searchAccountNumber').val();
        $scope.orderSearchObj.out_type = $('#searchOutType').val();
        EdeyeAdmin.post({
            url: '/orderInfo/recall/page',
            data: $scope.orderSearchObj,
        }, {
            SUCCESS: function (ret) {
                console.log(ret);
                if (ret.code === '200') {
                    EdeyeAdmin.setDataTableDataPhone(param, ret.data);
                }
            }
        });
    }
    $scope.search();

    $scope.submitData = {
        id: '',
        bid: '',
        cost_center: '',
        account_number: '',
        out_type: ''
    }

    $scope.status = function (id, bid) {
        $scope.submitData.id = id;
        $scope.submitData.bid = bid;
        $('#statusModal').modal('show');
    }

    $scope.submit = function () {
        $scope.submitData.cost_center = $('#statusCostCenter').val();
        $scope.submitData.account_number = $('#statusAccountNumber').val();
        $scope.submitData.out_type = $('#statusOutType').val();

        if($scope.submitData.cost_center == '') {
            EdeyeAdmin.closeMsg('请选择成本中心',true,1);
            return;
        }

        if($scope.submitData.account_number == '') {
            EdeyeAdmin.closeMsg('请选择科目号',true,1);
            return;
        }

        if($scope.submitData.out_type == '') {
            EdeyeAdmin.closeMsg('请选择类型',true,1);
            return;
        }

        layer.confirm('是否确定提交?', {
            btn: ['确认','取消'],
            closeBtn: false
        }, function() {
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });

            EdeyeAdmin.post({
                url: '/orderInfo/recall/submit',
                data: $scope.submitData,
            }, {
                SUCCESS: function (ret) {
                    layer.close(index);

                    EdeyeAdmin.closeMsg(ret.msg, true, 2);
                    if (ret.code == '500') {
                        return;
                    }

                    $('#statusModal').modal('hide');
                    $scope.submitData = {
                        id: '',
                        bid: '',
                        cost_center: '',
                        account_number: '',
                        out_type: ''
                    }

                    $scope.search();
                }
            });

        });
    }


}]);


